from PySide6.QtCore import QObject, Signal
import torch

class ModelLoader(QObject):
    model_loaded = Signal(object)

    def __init__(self):
        super().__init__()
        self.model = None
        self.model_path = None

    def load_model(self, model_path):
        try:
            model = torch.hub.load('./yolov5', 'custom', path=model_path, source='local')
            self.model = model
            self.model_path = model_path
            self.model_loaded.emit(model)
        except Exception as e:
            self.model_loaded.emit(None)